<?php

//require_once "../functions/imdb_api.php";
//require_once "../functions/tvrage.php";
//require_once "../functions/sort_main.php";

class index extends base {

    private $content;

    public function submenu() {
        $this->submenu = array();
        $this->submenu[0]["name"] = "Overview";
        $this->submenu[0]["callback"] = "overview";
        $this->submenu[0]["icon"] = "icons/cross.png";
        $this->submenu[0]["rights"] = 0;
        $this->submenu[0]["enabled"] = true;
        $this->_submenu($this->submenu);
    }

    public function run() {
        $this->submenu();
        $callback = $this->_run();
        if ($callback)
            $this->content = $this->$callback();
        $this->finish($this->content);
    }

    public function get_dir($dir) {
        $dh = opendir($dir);
        if (!$dh)
            return false;
        if ($dh) {
            while ($dir = readdir($dh)) {
                if ($dir != ".." && $dir != ".")
                    $data[] = array($dir);
            }
            closedir($dh);
        }
        return $data;
    }

    public function overview() {
        global $config;
        $this->page_manager->text_title("Waiting to be processed");
//        $sort_main = new sort_main($this->config, $this->db);
        $data = $this->get_dir($config["Directories"]["source"]);
        if (!$data)
            $data = array(array("Empty!"));
        $header = array(
            array("title" => "File", "color" => "green"),
        );
        $datac = array();
        foreach ($data as $item) {
            if ($item[0][0] == "-") {  //  Disabled, show in bold red
                $item[0] = "<font color='red'><strong>" . substr($item[0], 1, strlen($item[0]) - 1) . "</strong></font>";
            }
            $datac[] = $item;
        }
        $this->page_manager->style_table($header, $datac, true, $button, 1000, "show");

        $this->page_manager->text_title("Last 10 processed");
        $data = $this->db->sql("SELECT name FROM downloaded ORDER BY download_date DESC LIMIT 10");
        if (!$data)
            $data = array(array("Empty!"));
        $header = array(
            array("title" => "File", "color" => "green"),
        );
        $this->page_manager->style_table($header, $data, true, $button, 1000, "show");

        return $this->page_manager->web_content;
    }

}

?>